<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <div id="test"></div>
    <script src="./js/react.development.js"></script>
    <script src="./js/react-dom.development.js"></script>
    <script src="./js/babel.min.js"></script>
    <script type="text/babel">
        class Demo extends React.Component {
            state = {isHot:true}
            butClick = ()=>{
                const {input1} = this
                console.log(input1.value)
            }
            butClick2 = ()=>{
                const {isHot} = this.state
                this.setState({isHot:!isHot})
            }
            setInput = c => this.input1 = c
            render() {
                const {isHot} = this.state
                // ref如果修改虚拟DOM会调用两次ref中的回调,使用在类中定义回调可以解决这个问题，但是大部分情况下这个问题不会对代码有任何影响
                return (
                    <div>
                        <h1>今天天气很{isHot?'凉爽':'炎热'}</h1>
                        {/*<input ref={c=>{this.input1 = c;console.log('@')}} type="text" placeholder="点击按钮提示数据"/>*/}
                        <input ref={this.setInput} type="text"/>
                        <button onClick={this.butClick}>点击按钮提示数据</button>
                        <button onClick={this.butClick2}>点击切换天气</button>
                    </div>
                )
            }
        }
        ReactDOM.render(<Demo/>,document.getElementById("test"))
    </script>
</body>
</html>